import {
	request,
	baseUrl
} from "../request.js"

//域名 端口号
//var baseUrl = 'https://wzxlovemzy.com:6001/user'

/**
 * 1，根据账号密码登录
 * @param {Object} password 账号
 * @param {Object} username 密码
 * @param {Object} equipmentInfo 设备信息
 * @param {Object} deviceType 设备类型
 */
export function httpLoginByPwd(username, password, equipmentInfo, deviceType, code) {
	return request({
		url: baseUrl + '/login/login',
		method: 'POST',
		data: {
			username,
			password,
			equipmentInfo,
			deviceType,
			code: code || '',
		}
	})
}

/**
 * 2，获取验证码
 * @param {*} phone 手机号
 */
export function httpGetCode(phone) {
	return request({
		url: baseUrl + '/login/getYzm?phone=' + phone
	})
}

/**
 * 3，用户注册
 * @param {*} reqData 请求参数
 */
export function httpRegister(reqData) {
	return request({
		url: baseUrl + '/login/register',
		method: 'POST',
		data: {
			'nickname': reqData.nickname,
			'code': reqData.yzm,
			'phone': reqData.phone,
			'password': reqData.pwd
		}
	})
}

/**
 * 4，重置密码
 * @param {*} reqData 请求参数
 */
export function httpReset(reqData) {
	return request({
		url: baseUrl + '/login/reset',
		method: 'POST',
		data: {
			'code': reqData.code,
			'phone': reqData.phone,
			'password': reqData.pwd,
			'code': reqData.yzm
		}
	})
}

/**
 * 5，根据验证码登录
 * @param {Object} phone 手机号
 * @param {Object} code 验证码
 */
export function httpLoginByCode(phone, code, equipmentInfo, deviceType) {
	return request({
		url: baseUrl + '/login/loginByCode',
		method: 'POST',
		data: {
			phone,
			code,
			equipmentInfo,
			deviceType
		}
	})
}

/**
 * 6，根据旧密码修改新密码
 * @param {Object} password
 * @param {Object} newPassword
 */
export function updatePwd(password, newPassword) {
	return request({
		url: baseUrl + '/login/updatePwd',
		method: 'POST',
		data: {
			password,
			newPassword,
			userId: uni.getStorageSync('userId')
		}
	})
}

/**
 * 7，忘记密码发送验证码
 * @param {Object} phone
 */
export function forwardPwdSendCode(phone) {
	return request({
		url: baseUrl + '/login/forwardPwdSendCode?userId=' +
			uni.getStorageSync('userId') + '&phone=' + phone,
		method: 'GET'
	})
}

/**
 * 8，忘记密码设计新的密码
 * @param {Object} code
 * @param {Object} newPassword
 */
export function forwardPwd(code, newPassword, phone) {
	return request({
		url: baseUrl + '/login/forwardPwd',
		method: 'POST',
		data: {
			code,
			newPassword,
			userId: uni.getStorageSync('userId'),
			phone
		}
	})
}

/**
 * 9，注销
 */
export function logOff() {
	return request({
		url: baseUrl + '/login/logOff?userId=' +
			uni.getStorageSync('userId'),
		method: 'GET'
	})
}

/**
 * 10，手机号快捷登录
 */
export function loginByIphone(phone) {
	return request({
		url: baseUrl + '/login/loginByIphone?phone=' + phone,
		method: 'GET'
	})
}

/**
 * 11，游客登录
 */
export function loginByVisitor() {
	return request({
		url: baseUrl + '/login/loginByVisitor',
		method: 'GET'
	})
}